//
//  ASUINavigationController.m
//  AutoService
//
//  Created by OADUser on 2017/5/14.
//  Copyright © 2017年 OutsourceAX. All rights reserved.
//

#import "ASUINavigationController.h"

@interface ASUINavigationController ()

@end

@implementation ASUINavigationController

+ (instancetype)controllerWithRoot:(UIViewController *)rootViewController {
    return [[self alloc] initWithRootViewController:rootViewController];
}

-(id) initWithRootViewController:(UIViewController *)rootViewController
{
    self = [super initWithRootViewController:rootViewController];
    [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
    rootViewController.navigationItem.backBarButtonItem=nil;
    [rootViewController.navigationItem setHidesBackButton:NO];
[rootViewController.navigationController.navigationBar.backItem setHidesBackButton:NO];
rootViewController.navigationController.navigationBar.barTintColor=[UIColor blackColor];
rootViewController.navigationController.navigationBar.alpha=1.0;
    [rootViewController.navigationController.navigationBar setTranslucent:NO];

    
    [rootViewController.navigationController.navigationBar setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:18],NSForegroundColorAttributeName:[UIColor redColor]}];
    rootViewController.navigationController.navigationBar.barStyle = UIStatusBarStyleLightContent;
    [rootViewController.navigationController.navigationBar setTintColor:[UIColor redColor]];
    return self;
}

-(void) dismissController: (UIViewController *)viewController
{
    [self dismissViewControllerAnimated:YES completion:nil];
    [self popToRootViewControllerAnimated:YES];
}

- (void) setCloseButtonToController:(UIViewController *)viewController
{
    if (![viewController isFirstResponder])
    {
        UIButton *closeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [closeBtn setFrame:CGRectMake(0, 0, 20, 20)];
        [closeBtn addTarget:self action:@selector(dismissController:) forControlEvents:UIControlEventTouchUpInside];
        if ([[ UIDevice currentDevice].systemVersion floatValue] >=11.0) {
            closeBtn.imageEdgeInsets=UIEdgeInsetsMake(5, 5, 5, 5);
        } else {
        }
        [closeBtn setImage:[UIImage imageNamed:@"关闭"] forState:UIControlStateNormal];
        closeBtn.imageView.contentMode=UIViewContentModeScaleAspectFill;
        UIBarButtonItem *closeItem = [[UIBarButtonItem alloc]initWithCustomView:closeBtn];
        [viewController.navigationItem setRightBarButtonItem:closeItem animated:YES];
        
    }
    
}

- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    [super pushViewController:viewController animated:animated];
    [self setCloseButtonToController:viewController];
}

- (void)viewDidLoad {
    [super viewDidLoad];

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

@end
